/*
 * @Author: szx
 * @Date: 2022-05-21 13:58:40
 * @LastEditTime: 2022-05-21 14:09:54
 * @Description:
 * @FilePath: \leetcode\面试题\05\04\04.js
 */
/**
 * @param {number} num
 * @return {number[]}
 */
var findClosedNumbers = function (num) {
    // 这个测试用例超时哈哈
    if (num == 2147483647) return [-1, -1];
    function cntOne(num) {
        let cnt = 0;
        while (num != 0) {
            num &= num - 1;
            cnt++;
        }
        return cnt;
    }
    let cnt1 = cntOne(num);
    const res = [-1, -1];
    for (let i = num + 1; i < 2147483647; i++) {
        if (cntOne(i) == cnt1) {
            res[0] = i;
            break;
        }
    }
    for (let i = num - 1; i >= 0; i--) {
        if (cntOne(i) == cnt1) {
            res[1] = i;
            break;
        }
    }
    return res;
};
